package cn.edu.cug.cs.gtl.docsrv.auth.service.imp;

import cn.edu.cug.cs.gtl.docsrv.auth.dao.GroupDao;
import cn.edu.cug.cs.gtl.docsrv.auth.service.GroupService;
import cn.edu.cug.cs.gtl.mybatis.mapper.auth.AuthGroup;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class GroupServiceImpl implements GroupService {
    @Autowired
    GroupDao groupDao;

    @Override
    public boolean insertGroup(String authGroupJSON) {
        AuthGroup authGroup = JSON.parseObject(authGroupJSON, AuthGroup.class);
        if(authGroup!=null)
            return groupDao.insertGroup(authGroup);
        else
            return false;
    }

    @Override
    public boolean updateGroup(String authGroupJSON) {
        AuthGroup authGroup = JSON.parseObject(authGroupJSON, AuthGroup.class);
        if(authGroup!=null)
            return groupDao.updateGroup(authGroup);
        else
            return false;
    }

    @Override
    public boolean deleteGroup(String authGroupName) {
        return groupDao.deleteGroup(authGroupName);
    }

    @Override
    public String getGroup(String authGroupName) {
        AuthGroup authGroup = groupDao.getGroup(authGroupName);
        return JSON.toJSONString(authGroup);
    }
}
